package com.group.eams.service.impl;

import com.group.eams.entity.Discipline;
import com.group.eams.mapper.DisciplineMapper;
import com.group.eams.service.IDisciplineService;
import com.group.eams.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by 巧中 on 2016/11/4.
 */
@Service
public class DisciplineServiceImpl implements IDisciplineService{

    @Autowired
    private DisciplineMapper disciplineMapper;

    /**
     * 通过学科名字查询学科
     * @param name
     * @return
     */
    @Override
    public Discipline findDisciplineByName(String name) {
        return disciplineMapper.findDisciplineByName(name);
    }

    /**
     * 获取学科列表
     * @return
     */
    @Override
    public List<Discipline> getDisciplineList() {
        return disciplineMapper.getAllDiscipline();
    }

    /**
     * 通过id查询学科
     * @param id
     * @return
     */
    @Override
    public Discipline findDisciplineById(int id) {
        return disciplineMapper.findDisciplineById(id);
    }

    /**
     * 新增学科
     * @param discipline
     * @return
     */
    @Override
    public Result addDiscipline(Discipline discipline) {
        Result result = new Result();
        if (disciplineMapper.addDiscipline(discipline)) {
            result.setSuccess(true);
            result.setMessage("添加成功");
        }else{
            result.setSuccess(false);
            result.setMessage("添加失败");
        }
        return result;
    }

    /**
     * 更新学科信息
     * @param discipline
     * @return
     */
    @Override
    public Result updateDiscipline(Discipline discipline) {
        Result result = new Result();
        if (disciplineMapper.updateDiscipline(discipline)) {
            result.setSuccess(true);
            result.setMessage("更新成功");
        }else {
            result.setSuccess(false);
            result.setMessage("更新失败");
        }
        return result;
    }

    /**
     * 根据id删除学科信息
     * @param id
     * @return
     */
    @Override
    public Result deleteDisciplineById(int id) {
        Result result = new Result();
        if (disciplineMapper.deleteDisciplineById(id)) {
            result.setSuccess(true);
            result.setMessage("删除成功");
        }else {
            result.setSuccess(false);
            result.setMessage("删除失败");
        }
        return result;
    }
}
